package com.clubs.coding.utils;

import com.clubs.coding.Controller.MessageController;
import com.clubs.coding.Service.AppliCationService;
import com.clubs.coding.model.Vo.MessageVo;
import com.clubs.coding.model.dao.ApplicationMapper;
import com.clubs.coding.model.query.MesgList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {
    @Autowired
    AppliCationService appliCationService;

   public MesgList mesgList;
    ArrayList<String> objectArrayList = new ArrayList<>();

    public MesgList getMesgList() {
        return mesgList;
    }

    public void setMesgList(MesgList mesgList) {
        this.mesgList = mesgList;
    }

    //3.添加定时任务每天0点

    @Scheduled(cron = "0 0 0 * * ?")
//////    或直接指定时间间隔，例如：60秒
//    @Scheduled(fixedRate=10000)
    private void configureTasks() {
        System.out.println(this.getMesgList());
        if (this.getMesgList() !=null ) {
            List<MessageVo> messageVos = appliCationService.selectmesageVO(this.mesgList);
            for (int i = 0; i < messageVos.size(); i++) {
                MessageVo messageVo =  messageVos.get(i);
                if (messageVo.getLimitResidue()>4) {
                    System.out.println("在这里");
                    MessageController messageController = new MessageController();
                    messageController.go(messageVo.getOpenid());
                }
            }
        }

    }

}
